package com.example.materialviewpagerdemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.example.materialviewpagerdemo.bean.LeftListModel;
import com.example.materialviewpagerdemo.bean.StaticData;
import com.example.materialviewpagerdemo.util.SPHelper;
import com.example.materialviewpagerdemo.view.LeftListAdapter;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

public class DrawerActivity extends AppCompatActivity {
    private static final String TAG = "DrawerActivity";
    private DrawerLayout mDrawer;
    private ActionBarDrawerToggle mDrawerToggle;
    private ListView listView;
    List<LeftListModel> leftListModelList = new ArrayList<>();

    @Override
    protected void onStart() {
        super.onStart();

        leftListModelList.clear();
        listView = findViewById(R.id.listview);
        LeftListModel leftListModel = new LeftListModel();
        leftListModel.setImgId(R.drawable.qrcode);
        leftListModel.setItemContent("");
        leftListModelList.add(leftListModel);



        listView.setAdapter(new LeftListAdapter(this, leftListModelList));

        mDrawer = findViewById(R.id.drawer_layout);
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, 0, 0);
        mDrawer.setDrawerListener(mDrawerToggle);
        setTitle("");
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                switch (position) {
                    case 0:
                        EventBus.getDefault().post("0");
                        //DrawerActivity.this.startActivity(new Intent(DrawerActivity.this, QRActivity.class));

                    default:
                }
                close();
            }
        });

        final ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setDisplayShowHomeEnabled(true);
            actionBar.setDisplayShowTitleEnabled(true);
            actionBar.setDisplayUseLogoEnabled(false);
            actionBar.setHomeButtonEnabled(true);
        }

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        mDrawerToggle.syncState();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        return mDrawerToggle.onOptionsItemSelected(item) ||
                super.onOptionsItemSelected(item);
    }

    protected void close() {
        mDrawer.closeDrawers();
    }

}
